//! 自定义字符集示例

use unichar::{Unichar, CharacterSet, Style, Config};

fn main() {
    println!("=== Unichar 自定义字符集示例 ===\n");

    let mut unichar = Unichar::new();

    // 1. 添加自定义字符集
    println!("1. 添加自定义字符集:");
    
    let custom_smile = CharacterSet::new()
        .simple(":)")
        .icon("😊")
        .bold(":D")
        .color("😄");

    unichar.add_character_set("smile".to_string(), custom_smile);
    
    // 测试自定义字符
    for style in [Style::Simple, Style::Icon, Style::Bold, Style::Color] {
        unichar.set_config(Config::new().with_style(style.clone()));
        println!("   微笑 ({}): {}", 
                format!("{:?}", style).to_lowercase(),
                unichar.get("smile").unwrap_or("未找到"));
    }
    println!();

    // 2. 添加更多自定义字符
    println!("2. 添加更多自定义字符:");
    
    let custom_thumbs_up = CharacterSet::new()
        .simple("👍")
        .icon("👍")
        .bold("👍");

    let custom_thumbs_down = CharacterSet::new()
        .simple("👎")
        .icon("👎")
        .bold("👎");

    unichar.add_character_set("thumbs_up".to_string(), custom_thumbs_up);
    unichar.add_character_set("thumbs_down".to_string(), custom_thumbs_down);

    // 使用自定义字符
    println!("   点赞: {}", unichar.get("thumbs_up").unwrap_or("未找到"));
    println!("   点踩: {}", unichar.get("thumbs_down").unwrap_or("未找到"));
    println!();

    // 3. 使用自定义字符进行格式化
    println!("3. 使用自定义字符进行格式化:");
    println!("   {}", unichar.format("用户反馈: {thumbs_up} 或 {thumbs_down}"));
    println!("   {}", unichar.format("心情: {smile}"));
    println!();

    // 4. 创建主题相关的字符集
    println!("4. 创建主题相关的字符集:");
    
    // 编程相关字符
    let bug_char = CharacterSet::new()
        .simple("🐛")
        .icon("🐛")
        .bold("🐛");

    let feature_char = CharacterSet::new()
        .simple("✨")
        .icon("✨")
        .bold("✨");

    let refactor_char = CharacterSet::new()
        .simple("♻")
        .icon("♻️")
        .bold("♻");

    unichar.add_character_set("bug".to_string(), bug_char);
    unichar.add_character_set("feature".to_string(), feature_char);
    unichar.add_character_set("refactor".to_string(), refactor_char);

    // 演示编程主题
    println!("   修复: {}", unichar.get("bug").unwrap_or("未找到"));
    println!("   功能: {}", unichar.get("feature").unwrap_or("未找到"));
    println!("   重构: {}", unichar.get("refactor").unwrap_or("未找到"));
    println!();

    // 5. 批量操作自定义字符
    println!("5. 批量操作自定义字符:");
    let custom_chars = ["smile", "thumbs_up", "thumbs_down", "bug", "feature", "refactor"];
    let results = unichar.get_multiple(&custom_chars);
    
    for (name, char) in results {
        println!("   {}: {}", name, char.unwrap_or("未找到"));
    }
    println!();

    // 6. 检查字符是否存在
    println!("6. 检查字符是否存在:");
    let test_chars = ["smile", "success", "nonexistent", "thumbs_up"];
    for char_name in test_chars {
        let exists = unichar.has_character(char_name);
        println!("   {}: {}", char_name, if exists { "存在" } else { "不存在" });
    }
    println!();

    // 7. 获取更新后的统计信息
    println!("7. 更新后的统计信息:");
    let stats = unichar.get_stats();
    println!("   总字符数: {}", stats.total_characters);
    println!("   各样式支持数量:");
    for (style, count) in stats.style_counts {
        println!("     {:?}: {}", style, count);
    }
    println!();

    // 8. 移除自定义字符
    println!("8. 移除自定义字符:");
    if let Some(_removed) = unichar.remove_character_set("bug") {
        println!("   已移除 'bug' 字符集");
        println!("   移除后是否存在: {}", unichar.has_character("bug"));
    }
}
